package com.xiaoxi.exam.utils;


import com.xiaoxi.exam.bean.XzlXStream;

public class XMLUtils {

  private static final String ROOT_NODE_NAME_OF_RESPONSE = "xml";

  public static String toXml(Object obj, String alias, Class<?> zClass) {
    XzlXStream xStream = new XzlXStream();
    xStream.alias(alias, zClass);
    return xStream.toXML(obj);
  }

  @SuppressWarnings("unchecked")
  public static <T> T toBean(String xmlString, Class<T> zClass) {
    xmlString = xmlString.replaceAll(ROOT_NODE_NAME_OF_RESPONSE, zClass.getName());
    XzlXStream xStream = new XzlXStream();
    return (T) xStream.fromXML(xmlString);
  }
}
